﻿using System;
using System.Collections.Generic;
//using NHibernate;


namespace SessionPerPresenter.Data
{
    public class Dao<TEntity> : IDao<TEntity>
        where TEntity : class
    {
        private readonly ISessionProvider _sessionProvider;

        public Dao (ISessionProvider sessionProvider)
        {
            _sessionProvider = sessionProvider;
        }

        public IEnumerable<TEntity> GetAll()
        {
            var session = _sessionProvider.GetCurrentSession();
            IEnumerable<TEntity> results;
            using (var tx = session.BeginTransaction())
            {
                results = session.QueryOver<TEntity>()
                    .List<TEntity>();
                tx.Commit();
            }
            return results;
        }

        public void Dispose()
        {
            _sessionProvider.Dispose();
        }
    }

    
}
